package com.blue.test;

import java.util.List;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Page;

public class HelloController extends Controller {
	private int newsHead = 1;

	public void index() {

		int pageIndex = getParaToInt("pageIndex", 1);
		int pageSize = getParaToInt("pageSize", 20);
		Page<NewsImportant> userPage = NewsImportant.dao.paginate(pageIndex,
				pageSize, "select * ", " from newsimportant ");
		renderJson(userPage);

		// List<NewsImportant> list = NewsImportant.dao
		// .find("select * from newsimportant");
		// renderJson(list);
	}

	// 要闻按页获取
	public void getNewsInportant() {

		int pageIndex = getParaToInt("pageIndex", 1);
		int pageSize = getParaToInt("pageSize", 20);
		Page<NewsImportant> userPage = NewsImportant.dao.paginate(pageIndex,
				pageSize, "select *", "from newsimportant order by id sec");
		renderJson(userPage);
	}

	// 图片轮播器请求地址
	public void getNewsHead() {
		if (newsHead == 1) {
			newsHead = 2;
			List<NewsImportant> list = NewsImportant.dao
					.find("select * from newsimportant where type = 1");
			renderJson("list", list);
		} else if (newsHead == 2) {
			newsHead = 1;
			List<NewsImportant> list = NewsImportant.dao
					.find("select * from newsimportant where type = 2");
			renderJson("list", list);

		}
	}

}
